package com.itheima.demo;

import com.itheima.domain.Student;

import java.lang.reflect.Constructor;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/17 14:03
 */
@SuppressWarnings("all")
public class Demo_003 {
    public static void main(String[] args) throws NoSuchMethodException {
        Student stu = new Student();
        Class aClass = stu.getClass();
        //返回一个构造方法!
        Constructor constructor = aClass.getConstructor();
        System.out.println(constructor);
        //返回一个有两个参数的构造方法!
        Constructor constructor1 = aClass.getConstructor(String.class, int.class);
        System.out.println(constructor1);
        //返回单个构造方法!可以拿到private构造方法!
        Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
        System.out.println(declaredConstructor);

    }

    private static void method1(Class aClass) {
        //只能获取public修饰的方法;
        Constructor[] constructors = aClass.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }
    }
}
